package interviewType

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/interviewType"
	interviewTypeReq "github.com/flipped-aurora/gin-vue-admin/server/model/interviewType/request"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type InterviewTypeApi struct {
}

var interviewTypesService = service.ServiceGroupApp.InterviewTypeServiceGroup.InterviewTypeService

// CreateInterviewType 创建interviewType表
// @Tags InterviewType
// @Summary 创建interviewType表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body interviewType.InterviewType true "创建interviewType表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /interviewTypes/createInterviewType [post]
func (interviewTypesApi *InterviewTypeApi) CreateInterviewType(c *gin.Context) {
	//var interviewTypesInt interviewType.InterviewTypeInt
	var interviewTypes interviewType.InterviewType

	//var interviewTypesInt interviewType.InterviewTypeInt

	err := c.ShouldBindJSON(&interviewTypes)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	//pid :=

	//interviewtype := interviewType.InterviewType{
	//	GVA_MODEL: global.GVA_MODEL{},
	//	CreateAt:  interviewTypesInt.CreateAt,
	//	DeleteAt:  interviewTypesInt.DeleteAt,
	//	Level:     interviewTypesInt.Level,
	//	Name:      interviewTypesInt.Name,
	//	Pid:       interviewTypesInt.Pid,
	//	UpdateAt:  interviewTypesInt.UpdateAt,
	//	PidName:   "",
	//}

	if err := interviewTypesService.CreateInterviewType(&interviewTypes); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteInterviewType 删除interviewType表
// @Tags InterviewType
// @Summary 删除interviewType表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body interviewType.InterviewType true "删除interviewType表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /interviewTypes/deleteInterviewType [delete]
func (interviewTypesApi *InterviewTypeApi) DeleteInterviewType(c *gin.Context) {
	var interviewTypes interviewType.InterviewType
	err := c.ShouldBindJSON(&interviewTypes)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := interviewTypesService.DeleteInterviewType(interviewTypes); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteInterviewTypeByIds 批量删除interviewType表
// @Tags InterviewType
// @Summary 批量删除interviewType表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除interviewType表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /interviewTypes/deleteInterviewTypeByIds [delete]
func (interviewTypesApi *InterviewTypeApi) DeleteInterviewTypeByIds(c *gin.Context) {
	var IDS request.IdsReq
	err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := interviewTypesService.DeleteInterviewTypeByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateInterviewType 更新interviewType表
// @Tags InterviewType
// @Summary 更新interviewType表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body interviewType.InterviewType true "更新interviewType表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /interviewTypes/updateInterviewType [put]
func (interviewTypesApi *InterviewTypeApi) UpdateInterviewType(c *gin.Context) {
	var interviewTypes interviewType.InterviewType
	err := c.ShouldBindJSON(&interviewTypes)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := interviewTypesService.UpdateInterviewType(interviewTypes); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindInterviewType 用id查询interviewType表
// @Tags InterviewType
// @Summary 用id查询interviewType表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query interviewType.InterviewType true "用id查询interviewType表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /interviewTypes/findInterviewType [get]
func (interviewTypesApi *InterviewTypeApi) FindInterviewType(c *gin.Context) {
	var interviewTypes interviewType.InterviewType
	err := c.ShouldBindQuery(&interviewTypes)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if reinterviewTypes, err := interviewTypesService.GetInterviewType(interviewTypes.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reinterviewTypes": reinterviewTypes}, c)
	}
}

// GetInterviewTypeList 分页获取interviewType表列表
// @Tags InterviewType
// @Summary 分页获取interviewType表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query interviewTypeReq.InterviewTypeSearch true "分页获取interviewType表列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /interviewTypes/getInterviewTypeList [get]
func (interviewTypesApi *InterviewTypeApi) GetInterviewTypeList(c *gin.Context) {
	var pageInfo interviewTypeReq.InterviewTypeSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := interviewTypesService.GetInterviewTypeInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}
